package com.itheima.controller;

import com.itheima.bean.pojo.Role;
import com.itheima.bean.vo.Code;
import com.itheima.bean.vo.Result;
import com.itheima.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping
    @CrossOrigin
    public Result selectAllRole(){
        List<Role> roleList = roleService.queryRoles();

        Result responseResult = new Result(Code.GET_ERR, "查询失败");
        if (roleList!=null&!roleList.isEmpty()){
            responseResult=new Result(Code.GET_OK,roleList,"查询成功！");
        }
        return responseResult;
    }
}
